*===============================================================================
*Firm and Country Embedded Productivity (Alviarez, Cravino and Ramondo) 
*This is a master file containing all the codes in order to reproduce the estimates, figures and tables in the paper
*Last Modified by Vanessa Alviarez 03/2022
*Historical Orbis  
*===============================================================================

*-----------------------------------------------------------------------------
*Guidelines: 
*-----------------------------------------------------------------------------
*typeden==1 if "_ko" / *typeden==0 if "_exp_ko"
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF" /*option 1: lf "LF"; option 2: lf "". Likely this is the only option we want to have*/
*global lf "" /*option 1: lf "LF"; option 2: lf "". Includes companies with Limited financial information*/


*===============================================================================
*Step 1: Cleaning and organization of GENERAL AGGREGATE FILES 
*===============================================================================
/*
include "code/0_Cleaning_WDI.do" /*This file gdp_pc_ppp and gdp_pc_curr (last release 2020) */
include "code/0_Cleaning_WIOD.do" /*2016 relese (it has not been updated)*/
include "code/0_Cleaning_KLEMS.do" /*Uses the last release 2019*/ /*Notice it does not have the aggregated sectors */
include "code/0_Cleaning_KLEMS_India_individualfile.do"
include "code/0_Cleaning_GGDC.do"
include "code/0_Cleaning_OECD_STAN_rev4.do"
include "code/0_Cleaning_OECD_STAN_SDBS.do" \*this and "0_Cleaning_OECD_STAN_SDBS_10plus are old files I need to clean and likely erase*\
include "code/0_Cleaning_OECD_STAN_SDBS_bysize.do"

include "code/0_Cleaning_OECD_EXP.do"  
include "code/0_Cleaning_OECD_MNC.do"
include "code/0_Cleaning_Eurostat_MNC.do"
include "code/0_Cleaning_UNIDO.do" /*Output statistics for develop and developing countries, Manufacturing only*/

include "code/0_Cleaning_orbis_historical.do" /*Both for aggregate and firm level statistics*/ /*"${output}/firm_orbis_sales_selected_ctry.dta"*/ /* In contains tables: (new orbis and comparison with original file) ; uses "${orbis_historical}/mult_short_final_all_links_20200109" as main file for MNC firm level data*/
include "code/firm_tfp_part0_sales.do" /*A very short code now. Ready for regressions*/ /*"${output}/firm_allyears_sales.dta"*/
include "code/aggregate_data_sales.do" /*Last file "${output}/klems_oecd_unido_orbis_sales_emp_exp.dta". Still mnc have to be incorporated*/
include "code/aggregate_lp_klems.do" /*"${output}/aggregates_tfp_lp_klems.dta"; "${output}/aggregates_tfp_lp_klems_agg.dta"; "${output}/aggregates_tfp_lp_klems_agg_growth.dta" */
include "code/sectoral_weights.do" /*"${output}/sector_weights.dta"*/
*/


*===============================================================================
*Step 2: Preparing the dataset that is suitable for regressions
*===============================================================================
/*
*include "code/firm_tfp_part1_sales_emp.do"
*include "code/firm_tfp_part1_sales_emp_bvdid.do"
*include "code/firm_tfp_part1_sales_emp_bvdid_constant.do"
*include "code/firm_tfp_part1_sales_emp_LCS.do"
*include "code/firm_tfp_part1_sales_emp_withLF.do"
*include "code/firm_tfp_part1_sales_emp_10plus.do"
*include "code/firm_tfp_part1_sales_emp_TURN.do"
*include "code/firm_tfp_part1_sales_emp_TURN.do"
*include "code/master_reglist.do"
*/

*include "${code}/firm_tfp_part1_sales_emp_check.do"
*include "${code}/firm_tfp_part1_sales_emp.do"
*include "code/firm_tfp_part1_sales_emp_orbisagg_all.do"
*include "code/firm_tfp_part1_sales_emp_orbisagg_vawb.do"
*include "code/firm_tfp_part1_sales_emp_orbisagg_sawb.do"
*include "code/firm_tfp_part1_sales_emp_orbisagg_savawb.do"
*include "code/firm_tfp_part1_sales_emp_orbisagg_saemva.do"
*include "code/firm_tfp_part1_sales_emp_orbisagg_saemvawb.do"
*include "code/firm_tfp_part1_sales_emp_orbisagg_emva.do"
*include "code/firm_tfp_part1_sales_emp_orbisagg_saem.do"




*===============================================================================
*Step 3: NEW BATCH
*===============================================================================

*****************   BASELINE KLEMS (ckeck)  06/12/2022 ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set max_memory 300g
global lf "LF"
global conditionforage ""
include "code/firm_tfp_part1_sales_emp_orbisagg_all.do"


clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 62g

local heading "base_check"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"
local typeused "type" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"




*****************   BASELINE KLEMS (adjusting the baseline, extra==1 (selecting a set of country-sector pairs))  06/20/2022 --- undo this after ---******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 62g

local extra "0"
local heading "base_check"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"
local typeused "type" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"





*****************   BASELINE KLEMS (Excluding exports)  06/12/2022 ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 62g

local heading "base_exclexp"  
local varinterest sales_exp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"
local typeused "type" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   BASELINE KLEMS (Excluding exports -- ALT)  06/12/2022 ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 62g

local heading "base_exclexp_alt"  
local varinterest sales_exp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"
local typeused "type" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   BASELINE KLEMS (AGE >10)  06/12/2022 ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 62g

clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set max_memory 64g
global lf "LF"
global conditionforage `" keep if firm_age>=10"'
include "code/firm_tfp_part1_sales_emp_orbisagg_all.do"

local heading "base_aboveage10"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set max_memory 64g
global lf "LF"
global conditionforage ""
include "code/firm_tfp_part1_sales_emp_orbisagg_all.do"


*****************   BASELINE KLEMS (AGE >15)  06/12/2022 ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 62g

clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set max_memory 64g
global lf "LF"
global conditionforage `" keep if firm_age>=15"'
include "code/firm_tfp_part1_sales_emp_orbisagg_all.do"

local heading "base_aboveage15"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set max_memory 64g
global lf "LF"
global conditionforage ""
include "code/firm_tfp_part1_sales_emp_orbisagg_all.do"



*****************   BASELINE ORBIS (SALES)  06/12/2022 ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 62g

local heading "base_woparent_orbis_all"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"
local typeused "type" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   BASELINE ORBIS 100/50/20 (SALES)  06/12/2022 ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 62g
local number=20

local heading "base_woparent_orbis_all`number'"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"
local typeused "type" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"




*****************   BASELINE NEW (SALES)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_new"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE NEW (SALES) with both comp and sales  ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_sawbnew"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************  EMP *** BASELINE NEW (SALES) with both comp and sales  ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_saemnew"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE OLD (SALES)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_old"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE OLD (SALES) with both comp and sales  ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_sawbold"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE (ADJ new)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_adjnew"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

*****************   BASELINE (ADJ new **** EMP)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_adjnewem"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE (ADJ old)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_adj"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE (ADJ orbis)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_adjorbis"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE (ADJ orbis **** EMP)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local heading "base_woparent_adjorbisem"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   TOTAL EFFECT (BASE_newprime +  ADJ orbis)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
local rhoinitial=6

local heading "base_misdirect_adjorbis_rho`rhoinitial'"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


***************** ***  EMP **** TOTAL EFFECT (BASE_newprime +  ADJ orbis)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
local rhoinitial=8.5

local heading "base_misdirect_adjorbisem_rho`rhoinitial'"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   TOTAL EFFECT (BASE_newprime +  ADJ KLEMS)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
local rhoinitial=6

local heading "base_misdirect_adjnew_rho`rhoinitial'"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************  ***  EMP ****   TOTAL EFFECT (BASE_newprime +  ADJ KLEMS)   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
local rhoinitial=8.5

local heading "base_misdirect_adjnewem_rho`rhoinitial'"  
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"









*===============================================================================
*Step 3: Run each set of estimates under using different variables, samples and restrictions. 
*These regressions are by sector and also create their corresponding aggregates 
*===============================================================================

global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"


/*
*****************   BASELINE (SALES)   ******************
local heading "base_woparent"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"
*/

*****************   BASELINE (EMP)   ******************
local heading "base_woparent"  
local varinterest emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE (VA)   ******************
local heading "base_woparent"  
local varinterest va
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE (LABCOMP)   ******************
local heading "base_woparent"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"




*****************   MISALLOCATION INDIRECT (va/labcost)-- KLEMS   ******************
local heading "base_woparent_vawb"  
local varinterest va
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_vawb"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION INDIRECT (sales/labcost)-- KLEMS   ******************
local heading "base_woparent_sawb"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_sawb"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION INDIRECT (sales/emp)-- KLEMS   ******************
local heading "base_woparent_saem"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_saem"  
local varinterest emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION INDIRECT (sales/emp/va/labcost)-- KLEMS   ******************
local heading "base_woparent_saemvawb"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_saemvawb"  
local varinterest emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_saemvawb"  
local varinterest va
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_saemvawb"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION INDIRECT (sales/va/labcost)-- KLEMS   ******************
local heading "base_woparent_savawb"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_savawb"  
local varinterest va
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_savawb"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*=======================================================================================================================



*****************   MISALLOCATION INDIRECT (va/labcost)-- ORBIS   ******************
local heading "base_woparent_orbis_vawb"  
local varinterest va
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_orbis_vawb"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION INDIRECT (sales/labcost)-- ORBIS   ******************
local heading "base_woparent_orbis_sawb"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_orbis_sawb"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION INDIRECT (sales/emp)-- ORBIS   ******************
local heading "base_woparent_orbis_saem"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_orbis_saem"  
local varinterest emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION INDIRECT (sales/emp/va/labcost)-- ORBIS   ******************
local heading "base_woparent_orbis_saemvawb"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_orbis_saemvawb"  
local varinterest emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_orbis_saemvawb"  
local varinterest va
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_orbis_saemvawb"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION INDIRECT (sales/va/labcost)-- ORBIS   ******************
local heading "base_woparent_orbis_savawb"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_orbis_savawb"  
local varinterest va
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_orbis_savawb"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"




********** NEW *********
*****************   MISALLOCATION INDIRECT (sales KLEMS and sales/comp ORBIS)--   ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 64g

local heading "base_woparent_klemorbis1_klems"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_klemorbis1_orbis"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

local heading "base_woparent_klemorbis1_orbis"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"




********** NEW *********
*****************   MISALLOCATION INDIRECT (sales/comp KLEMS and sales/comp ORBIS)--   ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 64g

local heading "base_woparent_klemorbis2_klems"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 64g

local heading "base_woparent_klemorbis2_orbis"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"
set max_memory 64g

local heading "base_woparent_klemorbis2_orbis"  
local varinterest labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"







*********************MISALLOCATION DIRECT -- KLEMS-ORBIS (using the denominator from ORBIS calculated with firms for which the GROUP of variable is available)
*****************Calculate the dummies making sure each PAIR and ALL are not missing (no parents, sample 4, va/emp/sales/wagebill)************************
*Dummies with modify LHS with Klems/ORBIS (for all var combinations)
				* Share(LAB, Klems) + rho*[share(SALES, Orbis)-share(LAB, Orbis)]
                * Share(LAB, Klems) + rho*[share(VA, Orbis)-share(LAB, Orbis)]
                * Share(EMP, Klems) + rho*[share(SALES, Orbis)-share(EMP, Orbis)]
                * Share(EMP, Klems) + rho*[share(VA, Orbis)-share(EMP, Orbis)]
*Guide for the arguments this HEAD needs
*local endingargument vawb/sawb/vaem/saem
*local varinterest_a va/sa/va/sa
*local varinterest_b wb/wb/em/em



*****************   MISALLOCATION DIRECT (va/labcost)-- KLEMS/ORBIS   ******************
local rhoinitial=8.5
local heading "base_misdirect_klemsorbis"  
local endingargument vawb
local varinterest_a va
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION DIRECT (sales/labcost)-- KLEMS/ORBIS   ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set max_memory 64g
global lf "LF"

*Both rev and comp have to be available in Orbis and in Klems 
local rhoinitial=8.5
local heading "base_misdirect_klemsorbis"  
local endingargument sawb
local varinterest_a sales
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"

clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set max_memory 64g
global lf "LF"

**** NEW ****
*Rev has to be in Klems and Rev and Comp in Orbis
local rhoinitial=8.5
local heading "base_misdirect_klemsorbis_b"  
local endingargument sawb
local varinterest_a sales
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   MISALLOCATION DIRECT (va/emp)-- KLEMS/ORBIS   ******************
local rhoinitial=8.5
local heading "base_misdirect_klemsorbis"  
local endingargument emva
local varinterest_a va
local varinterest_b emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   MISALLOCATION DIRECT (sales/emp)-- KLEMS/ORBIS   ******************
local rhoinitial=8.5
local heading "base_misdirect_klemsorbis"  
local endingargument saem
local varinterest_a sales
local varinterest_b emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"




*********************MISALLOCATION DIRECT -- KLEMS ONLY (using the denominator from ORBIS calculated with firms for which the GROUP of variable is available)
*****************Calculate the dummies making sure each PAIR and ALL are not missing (no parents, sample 4, va/emp/sales/wagebill)************************
*Dummies with modify LHS with Klems/ORBIS (for all var combinations)
				* Share(LAB, Klems) + rho*[share(SALES, Orbis)-share(LAB, Orbis)]
                * Share(LAB, Klems) + rho*[share(VA, Orbis)-share(LAB, Orbis)]
                * Share(EMP, Klems) + rho*[share(SALES, Orbis)-share(EMP, Orbis)]
                * Share(EMP, Klems) + rho*[share(VA, Orbis)-share(EMP, Orbis)]
*Guide for the arguments this HEAD needs
*local endingargument vawb/sawb/vaem/saem
*local varinterest_a va/sa/va/sa
*local varinterest_b wb/wb/em/em



*****************   MISALLOCATION DIRECT (va/labcost)-- KLEMS ONLY   ******************
local rhoinitial=8.5
local heading "base_misdirect_klemsonly"  
local endingargument vawb
local varinterest_a va
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION DIRECT (sales/labcost)-- KLEMS ONLY   ******************
clear all
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local rhoinitial=8.5
local heading "base_misdirect_klemsonly"  
local endingargument sawb
local varinterest_a sales
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF"

local rhoinitial=8.5
local heading "base_misdirect_klemsonly_alphactte"  
local endingargument sawb
local varinterest_a sales
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   MISALLOCATION DIRECT (va/emp)-- KLEMS ONLY   ******************
local rhoinitial=8.5
local heading "base_misdirect_klemsonly"  
local endingargument emva
local varinterest_a va
local varinterest_b emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   MISALLOCATION DIRECT (sales/emp)-- KLEMS ONLY   ******************
local rhoinitial=8.5
local heading "base_misdirect_klemsonly"  
local endingargument saem
local varinterest_a sales
local varinterest_b emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"





*********************MISALLOCATION DIRECT -- ORBIS ONLY (using the denominator from ORBIS calculated with firms for which the GROUP of variable is available)
*****************Calculate the dummies making sure each PAIR and ALL are not missing (no parents, sample 4, va/emp/sales/wagebill)************************
*Dummies with modify LHS with Klems/ORBIS (for all var combinations)
				* Share(LAB, Klems) + rho*[share(SALES, Orbis)-share(LAB, Orbis)]
                * Share(LAB, Klems) + rho*[share(VA, Orbis)-share(LAB, Orbis)]
                * Share(EMP, Klems) + rho*[share(SALES, Orbis)-share(EMP, Orbis)]
                * Share(EMP, Klems) + rho*[share(VA, Orbis)-share(EMP, Orbis)]
*Guide for the arguments this HEAD needs
*local endingargument vawb/sawb/vaem/saem
*local varinterest_a va/sa/va/sa
*local varinterest_b wb/wb/em/em


*****************   MISALLOCATION DIRECT (va/labcost)-- ORBIS ONLY   ******************
local rhoinitial=8.5
local heading "base_misdirect_orbisonly"  
local endingargument vawb
local varinterest_a va
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION DIRECT (sales/labcost)-- ORBIS ONLY   ******************
clear all 
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF" 

local rhoinitial=8.5
local heading "base_misdirect_orbisonly"  
local endingargument sawb
local varinterest_a sales
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   MISALLOCATION DIRECT (sales/labcost) ADJUSTMENT-- ORBIS ONLY   ******************
global typeden=1
include "TFP_firm_directory_historical.do"
set memory 64g
global lf "LF" 

local rhoinitial=8.5
local heading "base_misdirect_orbisonly_adj"  
local endingargument sawb
local varinterest_a sales
local varinterest_b labcost
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"






*****************   MISALLOCATION DIRECT (va/emp)-- ORBIS ONLY   ******************
local rhoinitial=8.5
local heading "base_misdirect_orbisonly"  
local endingargument emva
local varinterest_a va
local varinterest_b emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"



*****************   MISALLOCATION DIRECT (sales/emp)-- ORBIS ONLY   ******************
local rhoinitial=8.5
local heading "base_misdirect_orbisonly"  
local endingargument saem
local varinterest_a sales
local varinterest_b emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
display "`title'"
include "${code}/firm_tfp_part2_reg_twowayFE.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"




























/*



*****************   BASELINE (SALES: using orbis as denominator)   ******************
local heading "base_woparent_orbisden"  
local varinterest sales
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
include "${code}/firm_tfp_part2_reg_twowayFE_temp.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE (VA: using orbis as denominator)   ******************
local heading "base_woparent_orbisden"  
local varinterest va
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
include "${code}/firm_tfp_part2_reg_twowayFE_temp.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"


*****************   BASELINE (EMP: using orbis as denominator)   ******************
local heading "base_woparent_orbisden"  
local varinterest emp
local timeframe `" "2016" "' 
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
include "${code}/firm_tfp_part2_reg_twowayFE_temp.do"
*Aggregating the sectoral estimates
include "${code}/firm_tfp_part2_reg_twowayFE_heading_temp.do"
local typeused "agg" /*type; agg*/
include "${code}/firm_tfp_part2_reg_aggregates_temp.do"












































***************** CHECK if useful *************************


*** I need to append these files so I can erase the individual files ***
**include "code/firm_tfp_part2(b)_reg_database.do" 
*------------------------------------------------------------------------
*THIRD PART: 
*------------------------------------------------------------------------


*Rho estimation 
*---------------------------------------------
*do fim_tfp_part4_rho_multi.do  /*This also contains now the uncorrelated regressions (check the management and other infraestructure)*/
*do firm_tfp_part4_rho_inst.do
*do firm_tfp_part4_rho_inst_v2.do /*Check this for the instruments*/


*Figures for the paper and presentation 
*----------------------------------------------
*do figures_presentation.do
*do firm_tfp_part3_fig3_multi.do 
*do figures_presentation(b)_copy.do /*I create a file called TFP firm\draft\Figures\figures_dataset_prelim.dta". This is the file Natalia is using to complete the file */








